#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2019
# @Author  : linhu (hlf0312@gmail.com)
# @Link    : TBD
# @Version : $Id$

from openpyxl import Workbook
from openpyxl import load_workbook
from collections import namedtuple
from time import strftime

JiraIssue = namedtuple('JiraIssue', 'itemId, key, summary, startFb, endFb, team, fbCommitStatus, estimated, \
	timeSpent, ΣTimeRemaining, status, assignee, stretchReason, delayReason, delayExplanation, competenceArea,\
	nokiaPrio, businessPrio1, plannedSystemRelease, targetPT, reporter, tribeLeader, featureTeam, entryEE, \
	problematicReasons, exitEE, contributionHours')

def buildJiraIssues(toBeValidatedExcelFile):

	wb = load_workbook(toBeValidatedExcelFile)
	ws = wb.active

	jiraIssues = []

	rowIndex = 2
	for row in ws.iter_rows(min_row=rowIndex):
		columnIndex = 1
		itemId = ws.cell(row=rowIndex, column=columnIndex).value
		key = ws.cell(row=rowIndex, column=columnIndex+1).value
		summary = ws.cell(row=rowIndex, column=columnIndex+2).value
		startFb = ws.cell(row=rowIndex, column=columnIndex+3).value
		endFb = ws.cell(row=rowIndex, column=columnIndex+4).value
		team = ws.cell(row=rowIndex, column=columnIndex+5).value
		fbCommitStatus = ws.cell(row=rowIndex, column=columnIndex+6).value
		estimated = ws.cell(row=rowIndex, column=columnIndex+7).value
		timeSpent = ws.cell(row=rowIndex, column=columnIndex+8).value
		ΣTimeRemaining = ws.cell(row=rowIndex, column=columnIndex+9).value
		status = ws.cell(row=rowIndex, column=columnIndex+10).value
		assignee = ws.cell(row=rowIndex, column=columnIndex+11).value
		stretchReason = ws.cell(row=rowIndex, column=columnIndex+12).value
		delayReason = ws.cell(row=rowIndex, column=columnIndex+13).value
		delayExplanation = ws.cell(row=rowIndex, column=columnIndex+14).value
		competenceArea = ws.cell(row=rowIndex, column=columnIndex+15).value
		nokiaPrio = ws.cell(row=rowIndex, column=columnIndex+16).value
		businessPrio1 = ws.cell(row=rowIndex, column=columnIndex+17).value
		plannedSystemRelease = ws.cell(row=rowIndex, column=columnIndex+18).value
		targetPT = ws.cell(row=rowIndex, column=columnIndex+19).value
		reporter = ws.cell(row=rowIndex, column=columnIndex+20).value
		tribeLeader = ws.cell(row=rowIndex, column=columnIndex+21).value
		featureTeam = ws.cell(row=rowIndex, column=columnIndex+22).value
		entryEE = ws.cell(row=rowIndex, column=columnIndex+23).value
		problematicReasons = []
		exitEE = 0
		contributionHours = 0

		jiraIssue = JiraIssue(itemId, key, summary, startFb, endFb, team, \
			fbCommitStatus, estimated, timeSpent, ΣTimeRemaining, status, \
			assignee, stretchReason, delayReason, delayExplanation, competenceArea, \
			nokiaPrio, businessPrio1, plannedSystemRelease, targetPT, reporter, tribeLeader, \
			featureTeam, entryEE, problematicReasons, exitEE, contributionHours)

		jiraIssues.append(jiraIssue)
		# print(jiraIssue)

		rowIndex += 1

	return jiraIssues